// pages/winePrizeInfo/index.js
import {
  UserAccountModel
} from '../../models/userAccount.js'
let userAccountModel = new UserAccountModel()
let start = 0
let end = 0

Page({

  /**
   * 页面的初始数据
   */
  data: {
    initDate: '2019-11-01 00:00:00',
    startYear: 2017,
    endYear: 2022,
    datas: [],
    count: 0,
    cost: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadData(start, end);
    
  },
  search() {
    console.log(start, end)
    this.loadData(start, end)
  },
  loadData(start, end){
    console.log(start, end)
    wx.showLoading({
      title: '发送中',
    })
    let account = userAccountModel.getWinInfo()
    account.then(
      res => {
        console.log(res)
        if (res.code == 1) {
          wx.stopPullDownRefresh();
          wx.hideLoading();
          this.setData({
            datas: res.data.winInfo,
            count: res.data.winInfo.length,
            cost: res.data.cost
          })
      
        } else {
          wx.stopPullDownRefresh();
          wx.hideLoading();

        }
      }
    ).catch(e => {
      wx.hideLoading();
      console.log(e)
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // 每次下拉刷新截止时间为当前时间
    var timestamp = Date.parse(new Date()) / 1000;
    if (end < timestamp) {
      end = timestamp
    }
    this.loadData(start, end);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  sendTimeToFather(e) {
    var data = e.detail.formatTime
    var format = data.replace(/-/g, '/')
    start = Date.parse(format) / 1000

  },
  sendTimeToFather1(e) {
    var data = e.detail.formatTime
    var format = data.replace(/-/g, '/')
    end = Date.parse(format) / 1000
  },
})